package com.gsnd.briuppts.web.controller;

import com.gsnd.briuppts.entity.CommonResult;
import com.gsnd.briuppts.entity.Student;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 自己写的服务可以返回出去哪些类型的数据
 * @Author: GX Cui
 * @Date 14:55 2024/6/19
 */

@RestController // 定义此处进行web的功能
@RequestMapping("/test") // 定义绑定的url地址
public class HelloController {


    // 纯文字
    // http://localhost:9999/test/1
    @RequestMapping("/1")
    public CommonResult test1(){
        CommonResult cr = new CommonResult();
        cr.setData("你好");
        return cr;
    }
    // 对象
    // http://localhost:9999/test/2
    @RequestMapping("/2")
    public CommonResult test2(){
        CommonResult cr = new CommonResult();
        Student student = new Student();
        student.setId(1);
        student.setName("张三");
        cr.setData(student);
        return cr;
    }
    // 集合
    // http://localhost:9999/test/3
    @RequestMapping("/3")
    public CommonResult test3(){
        CommonResult cr = new CommonResult();
        List<Integer> list = new ArrayList<>();
        list.add(4);
        list.add(2);
        list.add(6);
        cr.setData(list);
        return cr;
    }
}
